package com.beemindz.miyotee.provider;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;

public class TaskHelper {
	
	private static final String[] TASK_PROJECTION = new String[] { MyToDo.Tasks._ID, MyToDo.Tasks.COLUMN_NAME_ID,
	      MyToDo.Tasks.COLUMN_NAME_NAME, MyToDo.Tasks.COLUMN_NAME_DESCRIPTION, MyToDo.Tasks.COLUMN_NAME_REMINDER_DATE,
	      MyToDo.Tasks.COLUMN_NAME_CREATE_DATE, MyToDo.Tasks.COLUMN_NAME_UPDATE_DATE, MyToDo.Tasks.COLUMN_NAME_USER_NAME };
	
	private ContentResolver contentResolver;
	
	public TaskHelper(Context context) {
		this.contentResolver = context.getContentResolver();
	}
	
	/**
	 * Get all task.
	 * 
	 *  @return List task.
	 */
	public ArrayList<Task> loadAllTask() {
		ArrayList<Task> tasks = new ArrayList<Task>();
		
		Cursor cursor = contentResolver.query(MyToDo.Tasks.CONTENT_URI, TASK_PROJECTION, null, null, null);
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				int id = cursor.getInt(cursor.getColumnIndex(MyToDo.Tasks._ID));
				int idTask = cursor.getInt(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_ID));
				String nameTask = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_NAME));
				String desTask = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_DESCRIPTION));
				String reminderDate = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_REMINDER_DATE));
				String createdDate = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_CREATE_DATE));
				String updatedDate = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_UPDATE_DATE));
				String userName = cursor.getString(cursor.getColumnIndex(MyToDo.Tasks.COLUMN_NAME_USER_NAME));
				
				Task task = new Task(id, idTask, userName, nameTask, desTask, reminderDate, createdDate, updatedDate);
				tasks.add(task);
				cursor.moveToNext();
			}
		}
		
		return tasks;
	}
	
	/**
	 * Delete a task.
	 */
	public void deleteTask() {
	}
}
